package com.liwenfeng.diancanspringboot.controller.admin;

import com.liwenfeng.diancanspringboot.common.result.PageResult;
import com.liwenfeng.diancanspringboot.common.result.Result;
import com.liwenfeng.diancanspringboot.pojo.dto.StatementChangePlaceDTO;
import com.liwenfeng.diancanspringboot.pojo.dto.StatementDTO;
import com.liwenfeng.diancanspringboot.pojo.dto.StatementSubmitDTO;
import com.liwenfeng.diancanspringboot.pojo.entity.OrderDetail;
import com.liwenfeng.diancanspringboot.pojo.entity.Statement;
import com.liwenfeng.diancanspringboot.pojo.vo.StatementVO;
import com.liwenfeng.diancanspringboot.service.StatementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/statement")
@Slf4j
public class StatementController {
    @Autowired
    private StatementService statementService;

    // 按流水单号查询结算单列表带详情列表（浏览器端）
    @RequestMapping("/list")
    public Result<List<StatementVO>> list(Long turnoverId) {
        log.info("查询结算单列表，turnoverId:{}", turnoverId);
        if (turnoverId == null){
            return Result.error("流水单为空");
        }
        List<StatementVO> statementVOList = statementService.list(turnoverId);
        return Result.success(statementVOList);
    }

    // 提交结算单(浏览器端）
    @PostMapping("/submit")
    public Result<String> submit(@RequestBody StatementSubmitDTO statementSubmitDTO) {
        log.info("提交订单：{}", statementSubmitDTO);
        statementService.submit(statementSubmitDTO);
        return Result.success();
    }

    @GetMapping("/detail/{id}")
    public Result<List<OrderDetail>> getDetailById(@PathVariable Long id) {
        List<OrderDetail> orderDetailList = statementService.getOrderDetailByStatementId(id);
        return Result.success(orderDetailList);
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody Statement statement) {
        log.info("修改订单：{}", statement);
        statementService.update(statement);
        return Result.success();
    }
}
